package com.ruoyi.finance.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.finance.domain.TSubject;
import com.ruoyi.finance.service.ITSubjectService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;

/**
 * 科目表Controller
 * 
 * @author ruoyi
 * @date 2025-02-25
 */
@RestController
@RequestMapping("/subject")
public class TSubjectController extends BaseController
{
    @Autowired
    private ITSubjectService tSubjectService;

    /**
     * 查询科目表列表
     */
    @RequiresPermissions("finance:subject:list")
    @GetMapping("/list")
    public AjaxResult list(TSubject tSubject)
    {
        List<TSubject> list = tSubjectService.selectTSubjectList(tSubject);
        return success(list);
    }

    /**
     * 导出科目表列表
     */
    @RequiresPermissions("finance:subject:export")
    @Log(title = "科目表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TSubject tSubject)
    {
        List<TSubject> list = tSubjectService.selectTSubjectList(tSubject);
        ExcelUtil<TSubject> util = new ExcelUtil<TSubject>(TSubject.class);
        util.exportExcel(response, list, "科目表数据");
    }

    /**
     * 获取科目表详细信息
     */
    @RequiresPermissions("finance:subject:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tSubjectService.selectTSubjectById(id));
    }

    /**
     * 新增科目表
     */
    @RequiresPermissions("finance:subject:add")
    @Log(title = "科目表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated TSubject tSubject)
    {
        return toAjax(tSubjectService.insertTSubject(tSubject));
    }

    /**
     * 修改科目表
     */
    @RequiresPermissions("finance:subject:edit")
    @Log(title = "科目表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSubject tSubject)
    {
        return toAjax(tSubjectService.updateTSubject(tSubject));
    }

    /**
     * 删除科目表
     */
    @RequiresPermissions("finance:subject:remove")
    @Log(title = "科目表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tSubjectService.deleteTSubjectByIds(ids));
    }
}
